package com.buddies.lottery.ui.wallet.bank;

import com.buddies.lottery.base.BasePresenter;
import com.buddies.lottery.data.BaseObserver;
import com.buddies.lottery.data.DataManager;
import com.buddies.lottery.data.bean.Bank;
import com.buddies.lottery.data.bean.BankResponse;
import com.buddies.lottery.data.resp.CheckWalletPwdResponse;
import com.buddies.lottery.ui.wallet.pwd.UpdateWalletPwdContract;

/**
 * Created by xuliang on 2018/2/28.
 */

public class BankPresenter extends BasePresenter<BankContract.View> implements BankContract.Presenter {

    public BankPresenter(BankContract.View view) {
        super(view);
    }

    @Override
    public void loadBank() {
        addSubscription(DataManager.getInstance().getUserRepo().getBank(), new BaseObserver<BankResponse>() {
            @Override
            public void onNext(BankResponse response) {
                mView.onBankLoaded(response);
            }

            @Override
            public void onError(Throwable e) {
                mView.onError(e);
            }
        });
    }

    @Override
    public void postUpdateBank(String cardName, String cardNo, String cardUser, String walletPwd) {
        addSubscription(DataManager.getInstance().getUserRepo().postUpdateBank(cardName, cardNo, cardUser, walletPwd), new BaseObserver<Object>() {
            @Override
            public void onNext(Object response) {
                mView.onUpdateBankSuccess();
            }

            @Override
            public void onError(Throwable e) {
               mView.onError(e);
            }
        });
    }

    @Override
    public void checkWalletPwd(String pwd) {
        addSubscription(DataManager.getInstance().getUserRepo().checkWalletPwd(pwd), new BaseObserver<CheckWalletPwdResponse>() {
            @Override
            public void onNext(CheckWalletPwdResponse response) {
                mView.onCheckWalletPwdSuccess(response);
            }

            @Override
            public void onError(Throwable e) {
                mView.onError(e);
            }
        });
    }

}
